package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.AuthTeacherClassify;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.Staff;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 教师分类 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-05-26
 */
public interface AuthTeacherClassifyMapper extends BaseMapper<AuthTeacherClassify> {

    @Select({"<script>",
            "SELECT t1.* ",
            "FROM",
            "staff AS t1 ",
            "LEFT JOIN auth_teacher_classify AS t2 ON t1.id = t2.teacher_id ",
            "<when test='isRepetition==1'>",// 允许与其他分类重复，只排除当前分类已经添加过的成员
                "AND t2.type = ${type} ",
            "</when>",
            "WHERE",
            "t2.id IS NULL ",
            "<when test='schoolId!=null and schoolId!=&apos;&apos;'>",
                "AND t1.school_id in (${schoolId}) ",
            "</when>",
            "<when test='roleType!=null and roleType!=&apos;&apos;'>",
                "<when test='roleType==1'>",
                    "AND t1.id IN (SELECT admin_id FROM role_admin WHERE role_id IN ( 1568160887369994242 ))",
                "</when>",
                "<when test='roleType==2'>",
                    "AND t1.id IN (SELECT admin_id FROM role_admin WHERE role_id IN ( 1568160855895937026, 1568160855895937096 ))",
                "</when>",
            "</when>",
            "<when test='teacherName!=null and teacherName!=&apos;&apos;'>",
                "AND t1.name like '%${teacherName}%' ",
            "</when>",
            "</script>"})
    public List<Staff> getTeacherByClassify(@Param("isRepetition") Integer isRepetition,// 是否允许重复，0否1是
                                            @Param("roleType") Integer roleType, // 1校长 2老师
                                            @Param("type") Integer type,
                                            @Param("schoolId") String schoolId,
                                            @Param("teacherName") String teacherName
    );

}
